//
//  UIView+Animation.m
//  RealmeCommon
//
//  Created by 鲜权 on 2021/10/14.
//

#import "UIView+Animation.h"

@implementation UIView (Animation)
-(void)showScaleAnimationWithDuration:(CGFloat)duration
{
    [self showScaleAnimationWithDuration:duration anchorPoint:CGPointMake(0.5, 0.5)];
}
-(void)showScaleAnimationWithDuration:(CGFloat)duration anchorPoint:(CGPoint)anchorPoint
{
    CGRect frame = self.frame;
    self.layer.anchorPoint = anchorPoint;
    self.frame = frame;
    CABasicAnimation* animation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
    animation.duration = duration;
    animation.repeatCount = 1;
    animation.fromValue = @0;
    animation.toValue = @1;
    animation.removedOnCompletion = YES;
    [self.layer addAnimation:animation forKey:@"scale-show-layer"];
}
-(void)removeScaleAnimationWithDuration:(CGFloat)duration
{
    CABasicAnimation* animation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
    animation.duration = duration;
    animation.repeatCount = 1;
    animation.fromValue = @1;
    animation.toValue = @0;
    animation.removedOnCompletion = YES;
    animation.fillMode = @"forwards";
    [self.layer addAnimation:animation forKey:@"scale-remove-layer"];
}
@end
